/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.jesseenglish.swingftfy;

import com.jesseenglish.swingftfy.additions.CollapsibleJPanel;
import com.jesseenglish.swingftfy.extensions.FDialog;
import com.jesseenglish.swingftfy.extensions.FLabel;
import com.jesseenglish.swingftfy.extensions.FNode;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.util.Arrays;
import java.util.LinkedList;
import javax.swing.*;
import javax.swing.tree.DefaultTreeModel;

/**
 *
 * @author jesse
 */
public class ExamplesJFrame extends javax.swing.JFrame {
    
    private static ImageIcon ROOT = new ImageIcon(ExamplesJFrame.class.getResource("/images/root.png"));
    private static ImageIcon NODE = new ImageIcon(ExamplesJFrame.class.getResource("/images/node.png"));

    /**
     * Creates new form ExamplesJFrame
     */
    public ExamplesJFrame() {
        initComponents();
        
        loadExampleFTextField();
        loadExampleFTree();
        loadExampleFLabel();
        loadExampleFCheckBox();
        loadExampleFPanel();
        loadExampleDefaultFTabbedPane();
        loadExampleAccordionJPanel();
        loadExampleCollapsibleJPanel();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        MainJTabbedPane = new javax.swing.JTabbedPane();
        FTextFieldJPanel = new javax.swing.JPanel();
        ExampleFTextField = new com.jesseenglish.swingftfy.extensions.FTextField();
        jTextArea1 = new javax.swing.JTextArea();
        FTreeJPanel = new javax.swing.JPanel();
        ExampleFTree = new com.jesseenglish.swingftfy.extensions.FTree();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea2 = new javax.swing.JTextArea();
        FLabelJPanel = new javax.swing.JPanel();
        jTextArea3 = new javax.swing.JTextArea();
        ExampleFLabel = new com.jesseenglish.swingftfy.extensions.FLabel();
        FCheckBoxJPanel = new javax.swing.JPanel();
        jTextArea4 = new javax.swing.JTextArea();
        ExampleFCheckBox = new com.jesseenglish.swingftfy.extensions.FCheckBox();
        FDialogJPanel = new javax.swing.JPanel();
        jTextArea5 = new javax.swing.JTextArea();
        jButton1 = new javax.swing.JButton();
        FPanel = new javax.swing.JPanel();
        ExampleFPanel = new com.jesseenglish.swingftfy.extensions.FPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTextArea7 = new javax.swing.JTextArea();
        FTabbedPane = new javax.swing.JPanel();
        ExampleDefaultFTabbedPane = new com.jesseenglish.swingftfy.defaults.DefaultFTabbedPane();
        jScrollPane4 = new javax.swing.JScrollPane();
        jTextArea8 = new javax.swing.JTextArea();
        AccordionJPanel = new javax.swing.JPanel();
        ExampleAccordionJPanel = new com.jesseenglish.swingftfy.additions.AccordionJPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextArea6 = new javax.swing.JTextArea();
        CollapsibleJPanel = new javax.swing.JPanel();
        ExampleCollapisbleJPanel = new javax.swing.JPanel();
        jScrollPane5 = new javax.swing.JScrollPane();
        jTextArea9 = new javax.swing.JTextArea();
        DetailJPanel = new javax.swing.JPanel();
        ExampleDetailJPanel = new com.jesseenglish.swingftfy.additions.DetailJPanel();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane6 = new javax.swing.JScrollPane();
        jTextArea10 = new javax.swing.JTextArea();
        NavigationJPanel = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        LayoutsJPanel = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("SwingFTFY Examples");
        setPreferredSize(new java.awt.Dimension(500, 400));
        getContentPane().setLayout(new java.awt.GridLayout(1, 1));

        FTextFieldJPanel.setLayout(new java.awt.GridBagLayout());

        ExampleFTextField.setHintText("First Name");
        ExampleFTextField.setPreferredSize(new java.awt.Dimension(100, 28));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.PAGE_START;
        gridBagConstraints.weighty = 0.1;
        gridBagConstraints.insets = new java.awt.Insets(10, 0, 0, 0);
        FTextFieldJPanel.add(ExampleFTextField, gridBagConstraints);

        jTextArea1.setColumns(20);
        jTextArea1.setEditable(false);
        jTextArea1.setLineWrap(true);
        jTextArea1.setRows(5);
        jTextArea1.setText("The FTextField provides two main extensions to the a stock JTextField:\n\n1) Hint text is available; if the widget has no text value AND is not in focus, any hint text will appear\n2) Autocomplete is enabled; a list of strings will autocomplete - the example below includes \"Bob\", \"Joe\" and \"Sue\"");
        jTextArea1.setWrapStyleWord(true);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 0.1;
        FTextFieldJPanel.add(jTextArea1, gridBagConstraints);

        MainJTabbedPane.addTab("FTextField", FTextFieldJPanel);

        FTreeJPanel.setLayout(new java.awt.GridLayout(1, 2, 10, 0));
        FTreeJPanel.add(ExampleFTree);

        jTextArea2.setColumns(20);
        jTextArea2.setEditable(false);
        jTextArea2.setLineWrap(true);
        jTextArea2.setRows(5);
        jTextArea2.setText("The FTree provides several important extensions to JTree, some of which require using FNode objects in place of the common DefaultMutableTreeNode:\n\n1) FNodes have a setIcon method to quickly provide a customized look and feel\n2) FNodes respond directly to mouse events; extend an FNode and override any mouse event (to try this, right click on any of the child nodes)\n3) FTree provides handy \"expand all\" and \"expand node\" and \"get path\" methods\n4) FTree provides an easy way to change the background color of all nodes");
        jTextArea2.setWrapStyleWord(true);
        jScrollPane1.setViewportView(jTextArea2);

        FTreeJPanel.add(jScrollPane1);

        MainJTabbedPane.addTab("FTree", FTreeJPanel);

        FLabelJPanel.setLayout(new java.awt.GridBagLayout());

        jTextArea3.setColumns(20);
        jTextArea3.setEditable(false);
        jTextArea3.setLineWrap(true);
        jTextArea3.setRows(5);
        jTextArea3.setText("The FLabel adds a convenient way to set the bold property on the existing font without fiddling with the font directly.");
        jTextArea3.setWrapStyleWord(true);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 0.1;
        FLabelJPanel.add(jTextArea3, gridBagConstraints);

        ExampleFLabel.setText("This is a label that has been bolded.");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.PAGE_START;
        gridBagConstraints.weighty = 0.1;
        gridBagConstraints.insets = new java.awt.Insets(10, 0, 0, 0);
        FLabelJPanel.add(ExampleFLabel, gridBagConstraints);

        MainJTabbedPane.addTab("FLabel", FLabelJPanel);

        FCheckBoxJPanel.setLayout(new java.awt.GridBagLayout());

        jTextArea4.setColumns(20);
        jTextArea4.setEditable(false);
        jTextArea4.setLineWrap(true);
        jTextArea4.setRows(5);
        jTextArea4.setText("The FCheckBox provides a mechanism for displaying an icon on a JCheckBox without removing the checkbox image itself.\n\nThe FCheckBox is still a work in progress - to retrieve the label's text, you must use getUnmodifiedText() and to set an icon, you must provide either a URL or path (you cannot yet provide an existing Image or ImageIcon)\n");
        jTextArea4.setWrapStyleWord(true);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 0.1;
        FCheckBoxJPanel.add(jTextArea4, gridBagConstraints);

        ExampleFCheckBox.setText("A checkbox with an icon");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.PAGE_START;
        gridBagConstraints.weighty = 0.1;
        gridBagConstraints.insets = new java.awt.Insets(10, 0, 0, 0);
        FCheckBoxJPanel.add(ExampleFCheckBox, gridBagConstraints);

        MainJTabbedPane.addTab("FCheckBox", FCheckBoxJPanel);

        FDialogJPanel.setLayout(new java.awt.GridBagLayout());

        jTextArea5.setColumns(20);
        jTextArea5.setEditable(false);
        jTextArea5.setLineWrap(true);
        jTextArea5.setRows(5);
        jTextArea5.setText("The FDialog provides a method to center the dialog in its \nparent window.  Launch an example below.\n\n(Depending on when the dialog's size is calculated, the centering may be off; if you set the size before centering, this is not a problem).");
        jTextArea5.setWrapStyleWord(true);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 0.1;
        FDialogJPanel.add(jTextArea5, gridBagConstraints);

        jButton1.setText("Open Dialog");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.PAGE_START;
        gridBagConstraints.weighty = 0.1;
        gridBagConstraints.insets = new java.awt.Insets(10, 0, 0, 0);
        FDialogJPanel.add(jButton1, gridBagConstraints);

        MainJTabbedPane.addTab("FDialog", FDialogJPanel);

        FPanel.setLayout(new java.awt.GridLayout(1, 2, 10, 0));
        FPanel.add(ExampleFPanel);

        jTextArea7.setColumns(20);
        jTextArea7.setEditable(false);
        jTextArea7.setLineWrap(true);
        jTextArea7.setRows(5);
        jTextArea7.setText("FPanel facilitates background images (while maintaining a background color if desired).\n\nYou can set an image, and choose to repeat the image or not.\n\nIn the example here, the FPanel has a red background and a repeating image, with a JList tossed on top.");
        jTextArea7.setWrapStyleWord(true);
        jScrollPane3.setViewportView(jTextArea7);

        FPanel.add(jScrollPane3);

        MainJTabbedPane.addTab("FPanel", FPanel);

        FTabbedPane.setLayout(new java.awt.GridLayout(1, 2, 10, 0));
        FTabbedPane.add(ExampleDefaultFTabbedPane);

        jTextArea8.setColumns(20);
        jTextArea8.setEditable(false);
        jTextArea8.setLineWrap(true);
        jTextArea8.setRows(5);
        jTextArea8.setText("FTabbedPane provides a lot of useful functionality missing from the standard JTabbedPane.\n\n1) FTabbedPane provides \"close\" buttons on each tab desired.\n2) Tabs can be dragged back and forth if enabled.\n3) Tabs can be dragged off the current window and released - the expected functionality (which must be custom written) is the component becomes a new window (likely in a FTabbedPane as well).\n\nThese three functionalities are available but are abstracted from FTabbedPane; as such you must implement your own FTabbedPane and override four methods which effectively define how those functionalities behave.\n\nShown left is the DefaultFTabbedPane, which enables closing on all tabs, and disables rearranging and off-window dragging.");
        jTextArea8.setWrapStyleWord(true);
        jScrollPane4.setViewportView(jTextArea8);

        FTabbedPane.add(jScrollPane4);

        MainJTabbedPane.addTab("FTabbedPane", FTabbedPane);

        AccordionJPanel.setLayout(new java.awt.GridLayout(1, 2, 10, 0));
        AccordionJPanel.add(ExampleAccordionJPanel);

        jTextArea6.setColumns(20);
        jTextArea6.setEditable(false);
        jTextArea6.setLineWrap(true);
        jTextArea6.setRows(5);
        jTextArea6.setText("AccordionJPanel provides a complete layout implementation similar to a tabbed panel.\n\nYou can add a titled JPanel to have it render as a fold in the accordion.\n\nThe accordion has two modes: a single open fold, or multiple open folds.\n\nCurrently only JPanels are accepted as fold elements; hopefully this will be expanded to other components in the future.");
        jTextArea6.setWrapStyleWord(true);
        jScrollPane2.setViewportView(jTextArea6);

        AccordionJPanel.add(jScrollPane2);

        MainJTabbedPane.addTab("AccordionJPanel", AccordionJPanel);

        CollapsibleJPanel.setLayout(new java.awt.GridLayout(1, 2, 10, 0));

        ExampleCollapisbleJPanel.setLayout(new java.awt.GridBagLayout());
        CollapsibleJPanel.add(ExampleCollapisbleJPanel);

        jTextArea9.setColumns(20);
        jTextArea9.setEditable(false);
        jTextArea9.setLineWrap(true);
        jTextArea9.setRows(5);
        jTextArea9.setText("CollapsibleJPanel is a panel wrapped in a border with a title and a little \"collapse\" button.  Clicking the button will collpase the contents of the panel, hiding them from view.\n\nThe panel must be anchored to the top of its component window, otherwise the new size of the collapsed panel will cause it to render in the center of the screen (usually).\n\nTODO: Ideally this panel is replaced with a Border object instead.");
        jTextArea9.setWrapStyleWord(true);
        jScrollPane5.setViewportView(jTextArea9);

        CollapsibleJPanel.add(jScrollPane5);

        MainJTabbedPane.addTab("CollapsibleJPanel", CollapsibleJPanel);

        DetailJPanel.setLayout(new java.awt.GridLayout(1, 2, 10, 0));

        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("A Label Here");
        ExampleDetailJPanel.add(jLabel1);

        DetailJPanel.add(ExampleDetailJPanel);

        jTextArea10.setColumns(20);
        jTextArea10.setEditable(false);
        jTextArea10.setLineWrap(true);
        jTextArea10.setRows(5);
        jTextArea10.setText("DetailJPanel is a more modern rendering of what is commonly called a detail view.\n\nTypically these are rendered in a similar fashion to a context menu, but may not be interactive.\n\nThe DetailJPane is a JPanel, so anything can be put inside.\n\nTODO: Add a convenience method to slap a detail view onto the glasspane with a one-click removal mechanism.");
        jTextArea10.setWrapStyleWord(true);
        jScrollPane6.setViewportView(jTextArea10);

        DetailJPanel.add(jScrollPane6);

        MainJTabbedPane.addTab("DetailJPanel", DetailJPanel);

        jLabel3.setText("NavigationJPanel Coming Soon");
        NavigationJPanel.add(jLabel3);

        MainJTabbedPane.addTab("NavigationJPanel", NavigationJPanel);

        jLabel2.setText("Layouts Coming Soon");
        LayoutsJPanel.add(jLabel2);

        MainJTabbedPane.addTab("Layouts", LayoutsJPanel);

        getContentPane().add(MainJTabbedPane);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        FDialog d = new FDialog(this);
        d.add(new FLabel("Look at me!"));
        d.setSize(150, 50);
        d.center();
        d.setVisible(true);
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ExamplesJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ExamplesJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ExamplesJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ExamplesJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new ExamplesJFrame().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel AccordionJPanel;
    private javax.swing.JPanel CollapsibleJPanel;
    private javax.swing.JPanel DetailJPanel;
    private com.jesseenglish.swingftfy.additions.AccordionJPanel ExampleAccordionJPanel;
    private javax.swing.JPanel ExampleCollapisbleJPanel;
    private com.jesseenglish.swingftfy.defaults.DefaultFTabbedPane ExampleDefaultFTabbedPane;
    private com.jesseenglish.swingftfy.additions.DetailJPanel ExampleDetailJPanel;
    private com.jesseenglish.swingftfy.extensions.FCheckBox ExampleFCheckBox;
    private com.jesseenglish.swingftfy.extensions.FLabel ExampleFLabel;
    private com.jesseenglish.swingftfy.extensions.FPanel ExampleFPanel;
    private com.jesseenglish.swingftfy.extensions.FTextField ExampleFTextField;
    private com.jesseenglish.swingftfy.extensions.FTree ExampleFTree;
    private javax.swing.JPanel FCheckBoxJPanel;
    private javax.swing.JPanel FDialogJPanel;
    private javax.swing.JPanel FLabelJPanel;
    private javax.swing.JPanel FPanel;
    private javax.swing.JPanel FTabbedPane;
    private javax.swing.JPanel FTextFieldJPanel;
    private javax.swing.JPanel FTreeJPanel;
    private javax.swing.JPanel LayoutsJPanel;
    private javax.swing.JTabbedPane MainJTabbedPane;
    private javax.swing.JPanel NavigationJPanel;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextArea jTextArea10;
    private javax.swing.JTextArea jTextArea2;
    private javax.swing.JTextArea jTextArea3;
    private javax.swing.JTextArea jTextArea4;
    private javax.swing.JTextArea jTextArea5;
    private javax.swing.JTextArea jTextArea6;
    private javax.swing.JTextArea jTextArea7;
    private javax.swing.JTextArea jTextArea8;
    private javax.swing.JTextArea jTextArea9;
    // End of variables declaration//GEN-END:variables

    private void loadExampleFTextField() {
        ExampleFTextField.setAutoCompletes(new LinkedList(Arrays.asList(new String[] { "Bob", "Joe", "Sue" })));
    }
    
    private void loadExampleFTree() {
        FNode root = new FNode("Root");
        root.setIcon(ROOT);
        
        ExampleFNode child1 = new ExampleFNode("Child 1");        
        ExampleFNode child2 = new ExampleFNode("Child 2");
        ExampleFNode child3 = new ExampleFNode("Child 3");
        
        root.add(child1);
        root.add(child2);
        root.add(child3);
        
        DefaultTreeModel model = new DefaultTreeModel(root);
        ExampleFTree.setModel(model);
    }
    
    private void loadExampleFLabel() {
        ExampleFLabel.setBold(true);
    }
    
    private void loadExampleFCheckBox() {
        ExampleFCheckBox.setLabelIcon(ExamplesJFrame.class.getResource("/images/root.png"));
    }
    
    private void loadExampleFPanel() {
        ExampleFPanel.setBackground(Color.RED);
        ExampleFPanel.setImage((new ImageIcon(ExamplesJFrame.class.getResource("/images/root.png"))).getImage());
        ExampleFPanel.setRepeat(true);
        
        JList list = new JList();
        DefaultListModel model = new DefaultListModel();
        model.addElement("element -1");
        model.addElement("element -2");
        model.addElement("element -3");
        list.setModel(model);
        
        ExampleFPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
        ExampleFPanel.add(list);
    }
    
    private void loadExampleDefaultFTabbedPane() {
        ExampleDefaultFTabbedPane.removeAll();
        
        for (int i = 0; i < 3; i++) {
            JPanel panel = new JPanel(new FlowLayout(FlowLayout.CENTER));
            JButton reset = new JButton("Reset Example");
            reset.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent ae) {
                    loadExampleDefaultFTabbedPane();
                }
            });
            panel.add(reset);
            ExampleDefaultFTabbedPane.add("Tab " + i, panel);
        }
    }
    
    private void loadExampleAccordionJPanel() {
        
        for (int i = 0; i < 4; i++) {
            JList list = new JList();
            DefaultListModel model = new DefaultListModel();
            model.addElement("element " + i + "-1");
            model.addElement("element " + i + "-2");
            model.addElement("element " + i + "-3");
            list.setModel(model);
            
            JPanel containsList = new JPanel(new GridLayout(1, 1));
            containsList.add(list);
            ExampleAccordionJPanel.add("List " + i, containsList);
        }
        
    }
    
    private void loadExampleCollapsibleJPanel() {
        CollapsibleJPanel panel = new CollapsibleJPanel("Collapsible Example");
        
        JList list = new JList();
        DefaultListModel model = new DefaultListModel();
        model.addElement("element -1");
        model.addElement("element -2");
        model.addElement("element -3");
        list.setModel(model);
        
        panel.add(list);
        
        GridBagConstraints c = new GridBagConstraints();
        c.gridx = 0;
        c.gridy = 0;
        c.weightx = 0.1;
        c.weighty = 0.1;
        c.anchor = GridBagConstraints.NORTH;
        c.fill = GridBagConstraints.HORIZONTAL;
        
        ExampleCollapisbleJPanel.add(panel, c);
    }
    
    
    
    
    private class ExampleFNode extends FNode {

        public ExampleFNode(Object userObject) {
            super(userObject);
            this.setIcon(NODE);
        }

        @Override
        public void mouseReleased(MouseEvent me) {
            super.mouseReleased(me);
            
            if (SwingUtilities.isRightMouseButton(me)) {
                JPopupMenu menu = new JPopupMenu();
                menu.add(new JMenuItem("Thanks for clicking!"));
                
                Rectangle bounds = ExampleFTree.getPathBounds(ExampleFTree.getPath(this));
                menu.show(ExampleFTree, bounds.x, bounds.y + bounds.height);
            }
        }
        
    }

}
